package com.itheima.a04test;

import java.util.*;

public class Test4 {
    public static void main(String[] args) {
        //定义一个Map集合，键用省份表示province，值表示city，市有多个

        //定义一个Map集合
        HashMap<String, ArrayList<String>> hm=new HashMap<>();

        //创建一个List集合
        ArrayList<String> city1=new ArrayList<>();
        ArrayList<String> city2=new ArrayList<>();
        ArrayList<String> city3 =new ArrayList<>();
        Collections.addAll(city1,"南京市","扬州市","苏州市","无锡市","常州市");
        Collections.addAll(city2,"武汉市","孝感市","十堰市","宜昌市","鄂州市");
        Collections.addAll(city3,"石家庄市","唐山市","邢台市","保定市","张家口市");

        hm.put("江苏省",city1);
        hm.put("湖北省",city2);
        hm.put("河北省",city3);


        Set<Map.Entry<String, ArrayList<String>>> entrySet = hm.entrySet();
        for (Map.Entry<String, ArrayList<String>> entry : entrySet) {
            //
           StringJoiner sj=new StringJoiner(",","","");

            ArrayList<String> city = entry.getValue();
            for (String s : city) {
                sj.add(s);
            }
            System.out.println(entry.getKey() + "=" +sj);
        }

        //遍历
        //迭代器
        //创建迭代器对象
//        Iterator<String> it = al1.iterator();
//        while(it.hasNext()){
//            System.out.print(it.next()+"，");
//        }

        //lembda表达式
//        hm.forEach(new BiConsumer<String, ArrayList<String>>() {
//            @Override
//            public void accept(String s, ArrayList<String> strings) {
//                System.out.println(s+"="+strings);
//            }
//        });

        //增强for


    }
}
